<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<include file="Public:meta" />
	<style>
		.ChannelDepth1{padding-left:2px;}
		.ChannelDepth1 input{color:#00F;}
		.ChannelDepth2{padding-left:15px}
		.ChannelDepth3{padding-left:30px}
		.ChannelDepth4{padding-left:45px}
		.ChannelDepth5{padding-left:60px}
		.ChannelDepth6{padding-left:75px}
		.ChannelDepth7{padding-left:90px}
		.ChannelDepth8{padding-left:105px}
		table .tree{ cursor:pointer;}
	</style>
</head>
<body id="main_page">
<include file="Public:position" />
<div class="container"> 
   <form enctype="multipart/form-data" id="frm"  method="post">
          <div class="table">
            <div class="toolbars">
                <li class="toolbar"><a id="btnSaveAll" href="{$Url}Add" title="添加频道" target="_self">添加频道信息</a></li>
                <li class="toolbar"><a id="btnSaveAll" href="{$Url}batchAdd" title="批量添加频道" target="_self">批量添加频道</a></li>
                <li class="toolbar"><a id="btnSaveAll" href="{$Group}/label/index" title="频道属性标记管理" target="_self">属性标记管理</a></li>
                <li class="toolbar"><a id="btnSave" onclick="saveAll()"  title="保存所有修改">保存所有修改</a></li>
                <li class="toolbar" style="display:none"><a id="btnCache" onclick="clearChannelCache()"  title="当添加、删除、移动频道后，请清除频道缓存">清除频道缓存</a></li>
            </div>
            <table class="datatable" id="datatable">
                <tr>
                    <th width="45" >频道ID</th>
                    <th>频道名称</th> 
                    <th width="90">静态文件名称</th>
                    <th width="55" >频道排序</th>
                    <th width="55" >分页条数</th>
                    <th width="60">简短名称</th>  
                    <th width="55" >频道模型</th>            	
                    <th width="100" >首页模板</th>
                    <th width="120" >阅读模板</th>
                    <th width="188" >频道属性</th>
                    <th width="150">操作</th>
                </tr>
                <notempty name="Channel">
                <tbody>
                    <volist name="Channel" id="c">
                    <notin name="c.ChannelID" value="6,7,10,11">
                    <tr id="t{$c.ChannelID}" class="parent{$c.Parent}" cid="{$c.ChannelID}" haschild="{$c.HasChild}">
                    <td>{$c.ChannelID}<input type="hidden" name="ChannelID[]" value="{$c.ChannelID}" /></td>
                    <td  style="text-align:left" nowrap="nowrap">
                        <div class="ChannelDepth{$c.ChannelDepth}">
                        <eq name="c.HasChild" value="1">
                            <img src="{$Images}c{$c.HasChild}_open.gif" align="absmiddle" status="open" class="tree" onclick="ToggleChannel(this, {$c.ChannelID})" title="展开" />
                        <else/>
                            <img src="{$Images}c_line.gif" align="absmiddle" />
                        </eq>
                        <input type="text" class='textinput' style="width:100px" name="ChannelName[]" value="{$c.ChannelName}" />
                        </div>
                    </td>
                    <td><input type="text" class='textinput' style="width:90px" name="Html[]" value="{$c.Html}" /></td>
                    <td><input type="text" class='textinput' onclick="this.select()" style="width:50px" name="ChannelOrder[]" value="{$c.ChannelOrder}" /></td>
                    <td><input type="text" class='textinput' onclick="this.select()" style="width:50px" name="PageSize[]" value="{$c.PageSize}" />
                    </td>
                    <td><input type="text" class='textinput' style="width:60px" name="ChannelSName[]" value="{$c.ChannelSName}" /></td>
                    <td><b style="color:{$c.ChannelModelID|ChannelModelColor}">{$c.ChannelModelName}</b></td>                 
                    <td><input type="text" class='textinput' style="width:100px" name="IndexTemplate[]" value="{$c.IndexTemplate}" /></td>
                    <td><input type="text" class='textinput' style="width:120px" name="ReadTemplate[]" value="{$c.ReadTemplate}" /></td>
                    <td>
                        <notempty name="c.ChannelPicture"><b style="color:red" class="cp" value="{$c.ChannelPicture}">图</b>&nbsp;</notempty>
                        <eq name="c.IsHtml" value="1"><span style="color:#F0F">HTML</span></eq>&nbsp;
                        <eq name="c.IsSystem" value="1"><span style="color:#90F">系统</span>
                        <else/><span style="color:green">自定义</span>
                        </eq>&nbsp;
                        <eq name="c.IsLock" value="1">
                            <span style="color:red;cursor:pointer;"  onclick="toggleStatus(this,{$c.ChannelID},'channel','未锁',0,'blue','锁定',1,'red','IsLock')">锁定</span>
                        <else/>
                            <span style="color:blue;cursor:pointer;"  onclick="toggleStatus(this,{$c.ChannelID},'channel','未锁',0,'blue','锁定',1,'red','IsLock')">未锁</span>
                        </eq>&nbsp;
                        <eq name="c.IsShow" value="1">
                            <span style="color:#600;cursor:pointer;"  onclick="toggleStatus(this,{$c.ChannelID},'channel','隐藏',0,'#ccc','显示',1,'#600','IsShow')">显示</span>
                        <else/>
                            <span style="color:#CCC;cursor:pointer;"  onclick="toggleStatus(this,{$c.ChannelID},'channel','隐藏',0,'#ccc','显示',1,'#600','IsShow')">隐藏</span>
                        </eq>&nbsp;
                        <eq name="c.IsEnable" value="1">
                            <span style="color:#000;cursor:pointer;"  onclick="toggleStatus(this,{$c.ChannelID},'channel')">启用</span>
                        <else/>
                            <span style="color:#F00;cursor:pointer;"  onclick="toggleStatus(this,{$c.ChannelID},'channel')">禁用</span>
                        </eq>
                    </td>
                    <td  class="operator">
                        <if condition="$c.IsSystem eq 0" >
                            <if condition="$c.IsLock eq 0" >
                                <a style="float:left" href="{$Url}Modify/ChannelID/{$c.ChannelID}" id="btnEdit">修改</a>
                                <div class="btn-sep"></div>
                                <a style="float:left" onclick="DelChannel({$c.ChannelID})" class="btnDel">删除</a>
                            <else/>
                                <a style="float:left;" href="{$Url}Modify/ChannelID/{$c.ChannelID}" id="btnEdit">修改</a>
                            </if>
                        <else/>
                            <a style="float:left;" href="{$Url}Modify/ChannelID/{$c.ChannelID}" id="btnEdit">修改</a>        
                        </if>
                    </td>
                    </tr>
                    </notin>
                    </volist> 
                </tbody>
                <else/>
                	<tr><td colspan="11" id="NoData">{$Think.lang.NoDataTip}</td></tr>
                </notempty>                               
            </table>
             <div class="tfoot">
                  <div id="notice">
                        <b>备注：</b>
                        <span class="notice-item"><i>[1]</i>不能删除锁定频道和系统频道;</span>
                        <span class="notice-item"><i>[2]</i>当频道存在子频道时，必须先删除所有子频道，才能删除父级频道</span>
                        <span class="notice-item"><i>[3]</i>当频道存在数据时，必须先删除频道所有数据，才能删除频道</span>
                  </div>
             </div>
        </div>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
function DelChannel(id){
	$.confirm("{$Think.lang.DeleteTip}", function () {
		url = "{$Url}del/ChannelID/"+id;
		$.get(url, {}, DelChannelComplete, "json");
	}, function () {
		return true;
	});
}

//回调函数
function DelChannelComplete(data, textStatus){
	if (data.status == 1){
		$(data.data).css("display","none");
		RefreshLeftFrame();
	}else{ 
		//删除失败
		ErrorBox(data.info);
	}
}

//保存所有修改
function saveAll(){
	$.confirm("<div id='icon_common'>确定保存所有修改吗?</div>", function () {
		$('#frm').attr("action", "{$Url}saveAll");
		$('#frm').submit();
		RefreshLeftFrame();
	}, function () {
		return true;
	});
}	

function clearChannelCache(){
	url = "{$Url}clearCache/t/{:time()}";
	$.get(url, {}, ClearCacheComplete, "json");
	return true;
}
	//回调函数
function ClearCacheComplete(data, textStatus){
	if (data.status == 1){
		SucceedBox(data.info);
	}else{
		ErrorBox(data.info);
	}
}

//展开/收缩子频道
function ToggleChannel(obj, cid){
	var status = $(obj).attr("status");
	if(status == "open"){
		$(obj).attr("src", "{$Images}c1_close.gif");
		$(obj).attr("status", "close");
		$(obj).attr("title", "展开");
		closeChannel(cid);
	}else{
		$(obj).attr("src", "{$Images}c1_open.gif");
		$(obj).attr("status", "open");
		$(obj).attr("title", "收缩");
		openChannel(cid);
	}
	saveStatus();
}

//收缩
function closeChannel(cid){
	$(".parent"+cid).each(function() {
		$(this).hide();
		if( $(this).attr("haschild") == 1 && $(this).find(".tree").attr("status") == "open"  ){
			closeChannel( $(this).attr("cid") );
		}
	});
}

//展开
function openChannel(cid){
	$(".parent"+cid).each(function() {
		$(this).show();
		if( $(this).attr("haschild") == 1 && $(this).find(".tree").attr("status") == "open" ){
			openChannel( $(this).attr("cid") );
		}
	});
}

//保存树形菜单状态
function saveStatus(){
	var list = [];
	$(".datatable tbody tr").each(function() {
		if( $(this).attr("haschild") == 1 && $(this).find(".tree").attr("status") == "close"  ){
			list.push( $(this).attr("cid") );
		}
	});
	var all = ( list.length > 0 ) ? list.join(",") : null;
	$.cookie("{$Think.config.COOKIE_PREFIX}ChannelStatus", all, {path: '/', expiress:30} );　//expiress 有效日期，单位：天
}

//同步更新状态
function updateStatus(){
	var status = $.cookie("{$Think.config.COOKIE_PREFIX}ChannelStatus");
	if( status ){
		status = status.split(",");
		if( status.length > 0 ){
			for(var i = 0; i < status.length; i++){
				var obj = $("#t"+status[i]).find(".tree");
				obj.attr("src", "{$Images}c1_close.gif");
				obj.attr("status", "close");
				obj.attr("title", "展开");
				closeChannel( status[i] );
			}
		}
	}
}

$(document).ready(function(){
	updateStatus();
	$(".cp").powerFloat({
		targetMode: "ajax",
		targetAttr: "value",
		position: "5-7"
	 });
});
</script>